home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT11 / NOFLOPPY.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-29  |  7.7 KB  |  186 lines

  1. ;       Program NoFloppy ( Chapter 11 )
  2. ;
  3.     page    55,132
  4. _Text   segment para public 'CODE'
  5.     assume  cs:_Text
  6. ToOld:                                  ;=== Passing control to the old handler
  7.         db      0EAh            ; This is code for JMP FAR
  8. OldOff          dw      0               ; Here will be ofsset
  9. OldSeg          dw      0               ; Here will be segment
  10.  
  11. InActive        equ     0
  12. Active          equ     13h
  13. ActInd          db      0
  14. PresInd         dw      1951            ; This code is an indicator of presence
  15.  
  16. Handler label   byte                    ; Beginning of new handler for INT 13
  17.     cmp     ActInd,Active           ; Is the active mode set?
  18.     jne     ToOld                   ; If not, jump to the old handler
  19.     cmp     dl,79h                  ; Is the floppy disk requested?
  20.     ja      ToOld                   ; If not, jump to the old handler
  21.  
  22.     cmp     ah,03h                  ; Function 03 - write sector
  23.     je      WriSec                  ;    new handler for function 03
  24.     cmp     ah,0Bh                  ; Function 0B - write long sector
  25.     je      WriSecL                 ;    new handler for function 0Bh
  26. ;       cmp     ah,0Fh                  ; Function 0Fh - write buffer
  27. ;       je      WriBuf                  ;    new handler for function 0Fh
  28.     jmp     ToOld                   ; Others processed by old handler
  29.  
  30. WriSec:
  31. WriSecL:
  32. WriBuf:
  33.  
  34.     mov     ah,04h                  ; Function 04h - verify sector
  35.     jmp     ToOld                   ; Pass this fiunction to the handler
  36.  
  37. ;
  38. ;       End of new handler for interrupt 13h
  39. ;
  40.  
  41.  
  42. ;
  43. ;       NON - RESIDENT PART OF THE PROGRAM
  44. ;
  45. ParmInd db      0
  46. PspAddr dw      ?
  47. Start:
  48.     mov     PspAddr,es              ; Save address of PSP
  49.  
  50.     mov     ax,3513h                ; Get handler's address
  51.     int     21h                     ;    ES - segment, BX - offset
  52.     mov     ax,es:[bx-2]            ; Vector points to this handler ?
  53.     cmp     ax,cs:PresInd
  54.     je      Already                 ; If not - put message end exit  ========
  55. Install:                                ; Installation starts here
  56.     push    cs
  57.     pop     ds
  58.     mov     ah,09
  59.     lea     dx,BegMsg
  60.     int     21h
  61.     mov     cs:OldOff,bx            ; Save offsett of old handler
  62.     mov     cs:OldSeg,es            ; Save segment of old handler
  63.     mov     ax,cs                   ; Command segment of this program
  64.     mov     ds,ax                   ;    into DX (for setting handler)
  65.     cli                             ; Caution! critical part of program
  66.     mov     dx,offset Handler       ; Address of handler
  67.     mov     ax,2513h                ; Function 25h - Set new handler
  68.     int     21h                     ; Dos service call
  69.     sti                             ; Critical part finishes here
  70.     mov     ActInd,Active           ; Set activity ON
  71.     lea     dx,Loaded               ; DX - address of message
  72.     mov     ah,09h                  ; Function 09 - output string
  73.     int     21h                     ; DOS service call
  74.     lea     dx,INSTALL
  75.     add     dx,15
  76.     mov     cx,4                    ; Set counter for shift
  77.     shr     dx,cl                   ; 4 bits to the right - divide by 16
  78.     add     dx,16                   ; Add size of PSP
  79.     mov     ax,3100h                ; Terminate and
  80.     int     21h                     ;     state resident
  81.  
  82. NormExit:
  83.     mov     al,00h                  ; Return code = 0
  84.     jmp     FullExit                ; Print message and leave the program
  85.  
  86. ErrExit:
  87.     mov     al,01h                  ; Return code = 1
  88. FullExit:
  89.     push    ax                      ; Save return code
  90.     mov     ah,09h                  ; Function 09 - output string
  91.     int     21h                     ; DOS service call
  92.     pop     ax                      ; Restore return code
  93.     mov     ah,4Ch                  ; Function 4Ch - stop, return code AL
  94.     int     21h                     ; DOS service call
  95.  
  96. Already:
  97.     push    cs                      ; Copy the value of CS
  98.     pop     ds                      ;     into the register DS
  99.     mov     ax,PspAddr              ; Addres of PSP into AX
  100.     mov     es,ax                   ; ES now contains the segment of PSP
  101.     mov     bl,byte ptr es:[80h]    ; Get length of parameters
  102.     cmp     bl,1                    ; Are there parameters?
  103.     jle     NoParm                  ; If not, set the indicater "NoParm"
  104.     mov     bx,82h                  ; BX - the beginning of parameters
  105.     cmp     byte ptr es:[bx],'/'
  106.     jne     CheckS
  107. SkipSep:
  108.     inc     bx
  109.     jmp     CheckLet
  110. CheckS: cmp     byte ptr es:[bx],'-'
  111.     je      SkipSep
  112. CheckLet:
  113.     cmp     byte ptr es:[bx],'?'
  114.     je      Help
  115.     and     byte ptr es:[bx],0DFh   ; Force the first letter uppercase
  116.     cmp     byte ptr es:[bx],'H'
  117.     je      Help
  118.     cmp     byte ptr es:[bx],'O'    ; Is the first letter 'O'
  119.     jne     InvParm                 ; If not - missing or invalid
  120.     and     byte ptr es:[bx+1],0DFh ; Force the second letter uppercase
  121.     cmp     byte ptr es:[bx+1],'N'  ; Is the second letter 'N'?
  122.     je      TurnOn                  ; If not, check "OFF"
  123.     cmp     byte ptr es:[bx+1],'F'  ; Is the second letter 'F'?
  124.     jne     InvParm                 ; If not - invalid parameter
  125.     and     byte ptr es:[bx+2],0DFh ; Force the second letter uppercase
  126.     cmp     byte ptr es:[bx+2],'F'  ; Is the second letter 'N'
  127.     jne     InvParm                 ;
  128.     mov     ParmInd,InActive        ;
  129.     lea     dx,MakeOff              ;
  130.     jmp     Switch                  ;
  131.  
  132. TurnOn:
  133.     lea     dx,MakeOn               ;
  134.     mov     ParmInd,Active          ;
  135. Switch:
  136.     mov     ax,3513h                ; Get handler's address
  137.     int     21h                     ;    ES - segment, BX - offset
  138.     mov     al,Parmind              ;
  139.     mov     byte ptr es:[bx-3],al   ;
  140.     jmp     NormExit
  141. NoParm:
  142.     mov     ax,3513h                ; Get handler's address
  143.     int     21h                     ;    ES - segment, BX - offset
  144.     cmp     byte ptr es:[bx-3],Active
  145.     jne     IsOff                   ;
  146.     lea     dx,MakeOn               ;
  147.     jmp     NormExit                ;
  148. IsOff:  lea     dx,MakeOff              ;
  149.     jmp     NormExit                ;
  150. Help:   lea     dx,HelpTxt
  151.     jmp     NormExit
  152.  
  153. InvParm:
  154.     lea     dx,Invalid              ; DX := addres of message text
  155.     jmp     ErrExit
  156.  
  157. CR      equ     0Ah
  158. LF      equ     0Dh
  159. EndMsg  equ     24h
  160. BegMsg  db      CR,LF,'Floppy disk security system version 1.0',CR,LF
  161.     db      'Copyright (C) 1992 V.B.Maljugin,  Russia, Voronezh',CR,LF
  162. CRLF    db      CR,LF,EndMsg
  163. Invalid db      'Error - invalid parameters',CR,LF,EndMsg
  164. Loaded  db      'Floppy disk security system is installed!',CR,LF,EndMsg
  165. MakeOn  db      'Floppy disk security system is now on',CR,LF,EndMsg
  166. MakeOff db      'Floppy disk security system is now off',CR,LF,EndMsg
  167. HelpTxt db      CR,LF
  168.     db      CR,LF,'Program NoFloppy - Floppy Disk Security System        '
  169.     db      CR,LF,'Use it to surprise people who would like to share     '
  170.     db      CR,LF,'the information from your hard disk. ',CR,LF
  171.     db      CR,LF,'Usage:',CR,LF,'======',CR,LF
  172.     db      CR,LF,'NoFloppy [on | off | /? | /h | -? | -h] ',CR,LF
  173.     db      CR,LF,'Parameters:',CR,LF,'-----------',CR,LF
  174.     db      CR,LF,'on  - make the security system active                 '
  175.     db      CR,LF,'off - make the security system inactive               '
  176.     db      CR,LF,'rest of list - output this text                       '
  177.     db      CR,LF,'                                                      '
  178.     db      CR,LF,'Call program without parameter to report its          '
  179.     db      CR,LF,'current state.                                        '
  180.     db      CR,LF,'                                                      '
  181.     db      CR,LF,'Note: first progam call shouldn''t contain parameters '
  182.     db      CR,LF,'                                               '
  183.     db      CR,LF,EndMsg
  184. _text   ends
  185.     end     Start
  186.